import request from '@/utils/request'
import qs from 'qs'
import { AxiosPromise } from 'axios'
interface LoginOptions {
    phone: string
    password: string
}

const login = (data: LoginOptions): AxiosPromise<any> => {
  return request({
    method: 'POST',
    url: '/front/user/login',
    // 我们使用qs传递数据后，axios会自动帮我们推断content-type
    // headers: {
    //   'Content-Type': 'application/x-www-form-urlencoded'
    // },
    data: qs.stringify(data)
  })
}

const getInfo = (): AxiosPromise<any> => {
  return request({
    method: 'GET',
    url: '/front/user/getInfo'
  })
}

interface GetUserPagesType {
    currentPage?: number
    pageSize?: number
    phone?: number|null
    userId?: number|null
    startCreateTime?: string
    endCreateTime?: string
}
const getUserPages = (data: GetUserPagesType): AxiosPromise<any> => {
  return request({
    method: 'POST',
    url: '/boss/user/getUserPages',
    data
  })
}

const enableUser = (userId: number): AxiosPromise<any> => {
  return request({
    method: 'GET',
    url: '/boss/user/enableUser',
    params: {
      userId
    }
  })
}

interface ForbidUserType {
  userId: number
}

const forbidUser = (data: ForbidUserType): AxiosPromise<any> => {
  return request({
    method: 'POST',
    url: '/boss/user/forbidUser',
    data
  })
}

export {
  login,
  getInfo,
  getUserPages,
  enableUser,
  forbidUser
}
